package com.fengke.cn.yejian11.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.fengke.cn.yejian11.R;
import com.fengke.cn.yejian11.adapter.UserShaiTuAdapter;
import com.fengke.cn.yejian11.config.Config;
import com.fengke.cn.yejian11.impls.ActImpls;
import com.fengke.cn.yejian11.javabean.UserShaitu;
import com.squareup.picasso.Picasso;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class UserShaiTuActivity extends Activity {

    private RecyclerView recyclerView;
    private Retrofit retrofit;
    private UserShaiTuAdapter userShaiTuAdapter;
    private List<UserShaitu> userShaituList;
    private String User_Name;
    private String User_Id;
    private String User_Pic;
    private TextView user_name;
    private ImageView user_pic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_shai_tu);
        User_Id=getIntent().getStringExtra("User_Id");
        User_Name=getIntent().getStringExtra("User_Name");
        User_Pic=getIntent().getStringExtra("User_Pic");
        recyclerView= (RecyclerView) findViewById(R.id.user_shaitu_recyclerview);
        retrofit=new Retrofit.Builder()
                .baseUrl(Config.URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ActImpls service=retrofit.create(ActImpls.class);
        retrofit2.Call<List<UserShaitu>> call=service.getUserShaitu(User_Id);
        call.enqueue(new Callback<List<UserShaitu>>() {
            @Override
            public void onResponse(Call<List<UserShaitu>> call, Response<List<UserShaitu>> response) {
                List<UserShaitu> list=response.body();
                userShaiTuAdapter=new UserShaiTuAdapter(UserShaiTuActivity.this,list,User_Name,User_Pic);
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(UserShaiTuActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setAdapter(userShaiTuAdapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFailure(Call<List<UserShaitu>> call, Throwable t) {
                Toast.makeText(UserShaiTuActivity.this,"获取列表失败",Toast.LENGTH_SHORT).show();
            }
        });
    }
}
